using System.ComponentModel.DataAnnotations;

namespace DaprPlus.Identity.Options;

/// <summary>
/// Identity Server配置选项
/// </summary>
public class IdentityServerOptions
{
    public const string Position = "IdentityServer";

    /// <summary>
    /// 获取或设置 登录页面地址
    /// </summary>
    [Required]
    public string LoginPath { get; set; } = "/login";

    /// <summary>
    /// 获取或设置 Token端点
    /// </summary>
    [Required]
    public string TokenEndpoint { get; set; } = "/connect/token";

    /// <summary>
    /// 获取或设置 授权端点
    /// </summary>
    [Required]
    public string AuthorizeEndpoint { get; set; } = "/connect/authorize";

    /// <summary>
    /// 获取或设置 注销端点
    /// </summary>
    [Required]
    public string EndSessionEndpoint { get; set; } = "/connect/endsession";

    /// <summary>
    /// 获取或设置 用户信息端点
    /// </summary>
    [Required]
    public string UserInfoEndpoint { get; set; } = "/connect/userinfo";

    /// <summary>
    /// 获取或设置 令牌自省端点
    /// </summary>
    [Required]
    public string IntrospectionEndPoint { get; set; } = "/connect/introspection";

    /// <summary>
    /// 获取或设置 允许的作用域列表
    /// </summary>
    public string[] AllowedScopes { get; set; } = ["openid", "email", "profile", "roles", "phone"];

    /// <summary>
    /// 获取或设置 是否使用引用令牌
    /// </summary>
    public bool UseReferenceTokens { get; set; } = true;

    /// <summary>
    /// 获取或设置 是否禁用传输安全要求
    /// </summary>
    public bool DisableTransportSecurity { get; set; } = false;

    /// <summary>
    /// 获取或设置 证书配置
    /// </summary>
    public CertificateConfiguration Certificates { get; set; } = new();
}

/// <summary>
/// 证书配置
/// </summary>
public class CertificateConfiguration
{
    /// <summary>
    /// 获取或设置 是否使用开发证书
    /// </summary>
    public bool UseDevelopmentCertificates { get; set; }

    /// <summary>
    /// 获取或设置 加密证书配置
    /// </summary>
    public CertificateInfo? EncryptionCertificate { get; set; }

    /// <summary>
    /// 获取或设置 签名证书配置
    /// </summary>
    public CertificateInfo? SigningCertificate { get; set; }
}

/// <summary>
/// 证书信息
/// </summary>
public class CertificateInfo
{
    /// <summary>
    /// 获取或设置 证书路径
    /// </summary>
    public string? Path { get; set; }

    /// <summary>
    /// 获取或设置 证书密码文件路径
    /// </summary>
    public string? PassPhrasePath { get; set; }
}
